<template>
	<view id="user-recharge">
		<view class="content-box">
			<view class="h1">选择套餐</view>
			<view class="rechang-row">
				<view :class="['row-item',selectIndex == i?'row-act':'']" @click="getPrice(obj,i)" v-for="(obj,i) in rechangArr" :key="i">{{obj.price}}</view>
			</view>
			<view class="recharge-show">
				<view class="num">{{selectObj.price}}</view>
				<view class="tip">充值金额(元)</view>
			</view>
		</view>
		<view class="content-footer">
			<view class="footer-btn" @click="submitPay()">购买</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			rechangArr: [],
			selectIndex: 0,
			selectObj: {},
		};
	},
	onLoad() {
		this.getList();
	},
	components: {

	},
	onShow() {

	},
	methods: {
		openPopup(){
			// this.$api.msg('功能开发中')
		},
		// 选择套餐
		getPrice(obj,index){
			this.selectIndex = index;
			this.selectObj = obj;
		},
		getList(){
			this.$Request.request('/api/user_center/rechargePageInfo', 'GET', {}, true).then(res => {
				if (res.status == 1) {			
					this.rechangArr = res.data.rechargeItems;
					this.selectObj = this.rechangArr[this.selectIndex];
					// _this.accounts = res.data.rechargeItems
					// console.log(_this.accounts)
				}
			}).catch(err => {
				console.log(err)
			})
		},
		// 购买
		submitPay(){
			// 获取微信支付信息
			let params = {
				payObj: 'recharge',
				targetType: 0,
				needPay: this.selectObj.price,
				payCoce: 'weixinpays',
				itemId: this.selectObj.id,
				// trade_no: _this.trade_no
				from: 'uniapp',
			}
			this.$Request.request('/api/weixinpays/toWeixinPay', 'POST', params, true).then(res=>{
				console.log(res)
				if(res.status == 1){
					uni.requestPayment({
						"provider": "wxpay", 
						"orderInfo": res.data.orderInfo,
						success: res=> {
							console.log(res)
							this.$api.msg("充值成功!")
						},
						fail: err=> {
							console.log(err)
						}
					})
				}else {
					this.$api.msg(res.msg)
				}
			})
		},
	}
};
</script>

<style>
	page {
		background: #fff;
	}
</style>

<style scoped lang="scss">
	.content-box {
		width: 100%;
		padding: 54rpx 28rpx 0px;
		box-sizing: border-box;
		.h1 {
			margin-bottom: 32rpx;
			padding-left:24rpx;
			font-size: 28rpx;
			border-left: 6rpx solid $themLight;
		}
		.rechang-row {
			display: grid;
			grid-template-columns: 1fr 1fr 1fr;
			grid-column-gap: 24rpx;
			grid-row-gap: 32rpx;
			.row-item {
				width: 216rpx;
				height: 74rpx;
				border: 2rpx solid #BBBBBB;
				border-radius: 8rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 30rpx;
				color: #1D1E22;
				box-sizing: border-box;
			}
			.row-act {
				border: none;
				background: #EE486C;
				color: #fff;
			}
		}
		
		.recharge-show {
			padding: 120rpx 0px 130rpx;
			text-align: center;
			.num {
				font-size: 80rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #292929;
				line-height: 80rpx;
				margin-bottom: 28rpx;
			}
			.tip {
				font-size: 28rpx;
				font-weight: 600;
				color: #7A7C80;
				line-height: 40rpx;
			}
		}
	}
	
	.content-footer {
		width: 100%;
		padding: 0px 54rpx;
		box-sizing: border-box;
		.footer-btn {
			width: 100%;
			height: 76rpx;
			background: #EE486C;
			border-radius: 14rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 30rpx;
			color: #fff;
		}
	}
	
</style>
